package oj_leetcode;

public class MySqrt {
    public int mySqrt(int x) {
        long l = 1;
        long r = x;
        long res = 0;
        while (l <= r) {
            System.out.println(String.format("l - r = %s - %s", l, r));
            long mid = (l + r) / 2;
            res = mid * mid;
            System.out.println(res);
            System.out.println(x);
            if (res > x) {
                r = mid - 1;
            } else if (res < x) {
                l = mid + 1;
            } else {
                return (int) mid;
            }
        }
        return (int) r;
    }

    public static void main(String[] args) {
        System.out.println(new MySqrt().mySqrt(100000000));
    }
}
